import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def send_email(title,content):
    smtp_server = 'smtp.qq.com'
    smtp_port = 465  # 使用SSL加密，如果使用TLS加密则端口为587
    sender_email = '1124194029@qq.com'
    password = 'uvhifzximabqiege'  # 或授权码
    receiver_email = '497579916@qq.com'

    try:
        # 连接到SMTP服务器
        smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)  # 使用SSL加密
        # smtp = smtplib.SMTP(smtp_server, 587)  # 如果使用TLS加密，取消上一行并启用此行
        # smtp.starttls()  # 如果使用TLS加密，启用此行

        # 登录SMTP服务器
        smtp.login(sender_email, password)

        # 创建邮件对象
        msg = MIMEMultipart()
        msg['From'] = sender_email
        msg['To'] = receiver_email
        msg['Subject'] = title

        body = content
        msg.attach(MIMEText(body, 'plain'))

        # 发送邮件
        smtp.sendmail(sender_email, receiver_email, msg.as_string())
        print("Email sent successfully!")

    except Exception as e:
        print(f"Error: {e}")

    finally:
        # 关闭SMTP连接
        smtp.quit()

# 调用函数发送邮件
# send_email('1','2')
